package com.wdh.kjs.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdh.kjs.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class IM_raisesuccess_Adapter extends BaseAdapter {
    private List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    private Context context;
    private HashMap<String, String> maps = new HashMap<String, String>();
    private int periods = 0;

    public IM_raisesuccess_Adapter(Context context, List<HashMap<String, String>> data) {
        this.data = data;
        this.context = context;
    }

    public void resetData(List<HashMap<String, String>> data) {
        this.data.clear();
        this.data.addAll(data);
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();

            convertView = View.inflate(context, R.layout.fragment_invest_raisesuccess, null);

            viewHolder.raisesuccess_name = (TextView) convertView
                    .findViewById(R.id.raisesuccess_name);
            viewHolder.raisesuccess_annualRate = (TextView) convertView
                    .findViewById(R.id.raisesuccess_annualRate);
            viewHolder.raisesuccess_projectTime = (TextView) convertView
                    .findViewById(R.id.raisesuccess_projectTime);
            viewHolder.raisesuccess_repayType = (TextView) convertView
                    .findViewById(R.id.raisesuccess_repayType);
            viewHolder.raisesuccess_state = (TextView) convertView
                    .findViewById(R.id.raisesuccess_state);
            viewHolder.raisesuccess_starttime = (TextView) convertView
                    .findViewById(R.id.raisesuccess_starttime);
            viewHolder.raisesuccess_totalMoney = (TextView) convertView
                    .findViewById(R.id.raisesuccess_totalMoney);
            viewHolder.IM_raisesuccess_starttime_LinearLayout = (LinearLayout) convertView
                    .findViewById(R.id.IM_raisesuccess_starttime_LinearLayout);
            viewHolder.IM_raisesuccess_gone_LinearLayout = (LinearLayout) convertView
                    .findViewById(R.id.IM_raisesuccess_gone_LinearLayout);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        maps = data.get(position);
        viewHolder.raisesuccess_name.setText(maps.get("name"));
        viewHolder.raisesuccess_annualRate.setText(maps.get("annualRate"));
        viewHolder.raisesuccess_projectTime.setText(maps.get("projectTime"));
        viewHolder.raisesuccess_repayType.setText(maps.get("repayType"));
        viewHolder.raisesuccess_state.setText(maps.get("state"));
        viewHolder.raisesuccess_totalMoney.setText(maps.get("totalMoney"));
        if(maps.get("starttime").equals("-1")){
            viewHolder.IM_raisesuccess_starttime_LinearLayout.setVisibility(View.GONE);
        }else {
            viewHolder.raisesuccess_starttime.setText(maps.get("starttime"));
            viewHolder.IM_raisesuccess_starttime_LinearLayout.setVisibility(View.VISIBLE);
            viewHolder.IM_raisesuccess_gone_LinearLayout.setVisibility(View.GONE);
        }
        return convertView;
    }
    private class ViewHolder {
        TextView raisesuccess_name;
        TextView raisesuccess_annualRate;
        TextView raisesuccess_projectTime;
        TextView raisesuccess_repayType;
        TextView raisesuccess_starttime;
        TextView raisesuccess_state;
        TextView raisesuccess_totalMoney;
        LinearLayout IM_raisesuccess_starttime_LinearLayout;
        LinearLayout IM_raisesuccess_gone_LinearLayout;

    }


}
